package com.guojiaming.interview.second;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.guojiaming.interview.R;
import com.guojiaming.interview.second.adapter.PlayerDataAdapter;
import com.guojiaming.interview.second.adapter.PlayerInfoAdapter;
import com.guojiaming.interview.second.bean.PlayerInfo;

import java.util.List;

public class SecondActivity extends AppCompatActivity {

    private RecyclerView mRecyclerView;
    private PlayerInfoAdapter mPlayerInfoAdapter;
    private RecyclerView mRecyclerViewTab;
    private PlayerDataAdapter mPlayerDataAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_second);
        mRecyclerView = findViewById(R.id.rcv_main);
        mRecyclerViewTab = findViewById(R.id.rcv_tab);
        initView();
    }

    private void initView() {
        List<PlayerInfo> data = PlayerInfo.testData();
        mPlayerInfoAdapter = new PlayerInfoAdapter(R.layout.item_player_info_rcv, data);
        mRecyclerView.setAdapter(mPlayerInfoAdapter);
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        List<String> tabs = PlayerInfo.testTabData();
        mPlayerDataAdapter = new PlayerDataAdapter(R.layout.item_player_data_rcv, tabs);
        mRecyclerViewTab.setAdapter(mPlayerDataAdapter);
        mRecyclerViewTab.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false));
        mRecyclerViewTab.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(@NonNull RecyclerView recyclerView, int newState) {
                super.onScrollStateChanged(recyclerView, newState);
                mPlayerInfoAdapter.updateContentPosition(mRecyclerViewTab.computeHorizontalScrollOffset());
            }
        });
    }


    public static void jumpTo(Context context) {
        Intent intent = new Intent(context, SecondActivity.class);
        context.startActivity(intent);
    }
}
